/**
 * @author eunjae
 */

var data = [], totalPoints = 300;

function drawGraph(context) 
{
	function getData()
	{
		if (data.length > 0)
		{
			data = data.slice(1);
		}
		
		// do a random walk
        while (data.length < totalPoints) 
        {
			var prev = data.length > 0 ? data[data.length - 1] : 50;
			var y = context.jitter;
            
			if (y < 0)
				y = 0;
			if (y > 100)
				y = 100;
			data.push(y);
		}

        // zip the generated y values with the x values
        var res = [];
        for (var i = 0; i < data.length; ++i)
        {
            res.push([i, data[i]]);
       	}
        
        return res;
	}
		
	// setup plot
    var options = 
    {
        series: { shadowSize: 3 }, // drawing is faster without shadows
        yaxis: { min: 0, max: 100 },
        xaxis: { show: false }
    };
    
    var plot = $.plot($("#placeholder" + context.id), [ getData() ], options);
    plot.setData([ getData() ]);
    plot.draw();
}